package com.tjn.thread;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class ThreadState {
    public static void main(String[] args) throws InterruptedException {
        T2 t2 = new T2();
        System.out.println(t2.getName() + "的状态为：" + t2.getState());
        t2.start();
        while(Thread.State.TERMINATED != t2.getState()){//判断t2线程现在状态是否为终止（TERMINATED）状态
            System.out.println(t2.getName() + "的状态为：" + t2.getState());
            Thread.sleep(500);
        }
        System.out.println(t2.getName() + "的状态为：" + t2.getState());
    }
}
class T2 extends Thread{
    @Override
    public void run() {
        while (true) {
            for (int i = 0; i < 10; i++) {
                System.out.println("hi " + i);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            break;
        }
    }
}